local jinren = fk.CreateSkill({
    name = "sj3__jinren",
})
  
Fk:loadTranslationTable{
  ["sj3__jinren"] = "尽任",
  [":sj3__jinren"] = "当你失去非于本回合获得的牌时，若你已受伤，你可以摸一张牌。",

  ["@@sj3__jinren-inhand"] = "尽任",

  ["$sj3__jinren1"] = "",
  ["$sj3__jinren2"] = "",
}

--[[
jinren:addEffect(fk.BeforeCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(jinren.name) and player:isWounded() then
      for _, move in ipairs(data) do
        return move.from == player and table.find(move.moveInfo,function (info)
          return (info.fromArea == Player.Hand or info.fromArea == Player.Equip) and Fk:getCardById(info.cardId):getMark("@@sj3__jinren-inhand") ~= 0
        end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1,jinren.name)
  end,
})
--]]

  jinren:addEffect(fk.AfterCardsMove, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
      if player:hasSkill(jinren.name) and player:isWounded() then
        for _, move in ipairs(data) do
          return move.from == player and table.find(move.moveInfo,function (info)
            return (info.fromArea == Player.Hand or info.fromArea == Player.Equip) and
            #player.room.logic:getEventsOfScope(GameEvent.MoveCards,1,function (e)
              for _, m in ipairs(e.data) do
                if m.to == player and (m.toArea == Player.Hand or m.toArea == Player.Equip) and table.find(m.moveInfo, function (i)
                    return i.cardId == info.cardId
                  end) then
                  return true
                end
              end
            end,Player.HistoryTurn) == 0
          end)
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      player:drawCards(1,jinren.name)
    end,
  })
  
--添加标记，便于尽任的延迟记忆
  jinren:addEffect(fk.BeforeTurnStart, {
    mute = true,
    can_refresh = function(self, event, target, player, data)
      return player:hasSkill(jinren.name)
    end,
    on_refresh = function(self, event, target, player, data)
      for _, id in ipairs(player:getCardIds("he")) do
        player.room:setCardMark(Fk:getCardById(id),"@@sj3__jinren-inhand",1)
      end
    end,
  })

  jinren.onAcquire = function (self, player, is_start)
    for _, id in ipairs(player:getCardIds("he")) do
      if #player.room.logic:getEventsOfScope(GameEvent.MoveCards,1,function (e)
        for _, m in ipairs(e.data) do
          if m.to == player and (m.toArea == Player.Hand or m.toArea == Player.Equip) and table.find(m.moveInfo, function (i)
              return i.cardId == id
            end) then
            return true
          end
        end
      end,Player.HistoryTurn) > 0 then
        player.room:setCardMark(Fk:getCardById(id),"@@sj3__jinren-inhand",1)
      end
    end
  end

  jinren.onLose = function (self, player, is_death)
    for _, id in ipairs(player:getCardIds("he")) do
      player.room:setCardMark(Fk:getCardById(id),"@@sj3__jinren-inhand",0)
    end
  end

  return jinren